{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc62ea78",
   "metadata": {},
   "outputs": [],
   "source": [
    "# class --内部》 成员变量（属性），成员方法（一般是实例方法self，还有静态方法cls，类方法,none），专有方法\n",
    "# class --外部》 对象（类构造出的，调用 init） == 实例 （类实例化的，调用 init）\n",
    "class Student:\n",
    "    def __init__(self,na,ag,se): #__init__()是构造函数，构造了Student的参数，即下文中的s，会被自动调用。最重要的作用是构造变量，即对象\n",
    "        self.name = na #定义name这个变量，在类中定义变量需要加上self.xxx\n",
    "        self.age = ag\n",
    "        self.sex = se\n",
    "        print('构造Student的对象')\n",
    "    def info(self): #实例方法中括号内必须有默认的第一个参数即self\n",
    "        print('name : ',self.name,'\\nage : ',self.age,'\\nsex : ',self.sex)\n",
    "if __name__ == '__main__': #程序入口要写在类外面，用==来判断name是否等于main\n",
    "    s = Student('YYY',16,'female') #--> m默认调用 init\n",
    "    s.info() #用这个实例去调用\n",
    "    print(s) #输出地址，不用写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a4c2d7c9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wozai 构造\n",
      "名称：黄海\n",
      "地址：北纬37度\n",
      "深度（km）：1000\n",
      "温度（摄氏度）：24\n",
      "['黄海', '北纬37度', 1000, 24]\n",
      "wozai 构造\n",
      "名称：东海\n",
      "地址：北纬30度\n",
      "深度（km）：2000\n",
      "温度（摄氏度）：28\n"
     ]
    }
   ],
   "source": [
    "class Sea:\n",
    "    def __init__(self, name, location, depth, temperature):\n",
    "        self.name = name\n",
    "        self.location = location\n",
    "        self.depth = depth\n",
    "        self.temperature = temperature\n",
    "        print(\"wozai 构造\")\n",
    "    def info(self):\n",
    "        print('名称：{}\\n地址：{}\\n深度（km）：{}\\n温度（摄氏度）：{}'.format(\n",
    "            self.name, self.location, self.depth, self.temperature))\n",
    "if __name__ == '__main__':\n",
    "    # class 自定义类型\n",
    "    Yellow_Sea = Sea('黄海', '北纬37度', 1000, 24)\n",
    "    Yellow_Sea.info()\n",
    "\n",
    "    Yellow_Sea = ['黄海', '北纬37度', 1000, 24]\n",
    "    print(Yellow_Sea)\n",
    "\n",
    "    Earth_Sea = Sea('东海', '北纬30度', 2000, 28)\n",
    "    Earth_Sea.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ddf212e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 一部分专有方法\n",
    "class person():\n",
    "    def __init__(self,name,age,weight):\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "        self.__weight = weight\n",
    "    def __pow__(self):\n",
    "        pow_age = self.age.__pow__(2)\n",
    "        print(pow_age)\n",
    "    def __len__(self):\n",
    "        name_del = self.name.__len__()\n",
    "        print(name_del)\n",
    "    def __add__(self):\n",
    "        adds = self.age.__add__(self.__weight)\n",
    "        print(adds)\n",
    "    def infoma(self):\n",
    "        print('%s is %s weights %s'%(self.name,self.age,self.__weight))\n",
    "print(person.__class__) #输出person类的类型，是type（一个最顶层的类型）\n",
    "print(person.__repr__)\n",
    "per1 = person('bruce',25,60)\n",
    "print(type(per1)) #per1的类型是person（就好比list、set等）\n",
    "per1.infoma()\n",
    "\n",
    "#cmp = person.__cmp__()\n",
    "#lens = person.__len__()\n",
    "#adds = person.__add__()\n",
    "#print('doc is %s'%person.__doc__)\n",
    "#print('dir is %s'%person.__dir__)\n",
    "#print('delatter is %s'%person.__delattr__)\n",
    "#print('gt is %s'%person.__gt__)\n",
    "#print('hash is %s'%person.__hash__)\n",
    "#print('init is %s'%person.__init__)\n",
    "#print('new is %s'%person.__new__)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40bffe36",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
